﻿@{
    Layout = "~/Views/Shared/_detail.cshtml";
    if (false)
    {
        <script src="~/LiberUI/Scripts/jquery.js"></script>
        <script src="~/LiberUI/Scripts/LiberUI.Base.js"></script>
        <script src="~/LiberUI/Scripts/LiberUI.js"></script>
        <script src="~/LiberUI/Scripts/LiberUI.Action.js"></script>
    }
    <link href="~/SiteUI/Company/NewCopany.css" rel="stylesheet" />
}
<div class="row">
    <div class="col-lg-12" id="CompanyCertification">
        <div class="row" id="pageTitle">
            <h4>天联云平台-创建企业</h4>
        </div>
        <div class="row" id="certifyInfo">
            <div class="col-lg-12">
                <div class="row sectionTitle">
                    <h5>企业基本信息</h5>
                </div>
                <div class="row infoField">
                    <div class="col-lg-2 if-title">
                        企业全称
                    </div>
                    <div class="col-lg-5 if-input">
                        <input maxlength="200" id="nc-name" />
                        <p>只支持中国大陆工商局或市场监督管理局登记的企业。请填写工商营业执照上的企业全称。</p>
                    </div>
                    <div class="col-lg-5 if-memo" id="ifm-name">
                    </div>
                </div>
                <div class="row infoField">
                    <div class="col-lg-2 if-title">
                        注册地址
                    </div>
                    <div class="col-lg-5 if-input">
                        <input maxlength="500" id="nc-address" />
                    </div>
                    <div class="col-lg-5 if-memo" id="ifm-address">

                    </div>
                </div>
                <div class="row infoField">
                    <div class="col-lg-2 if-title">
                        联系电话
                    </div>
                    <div class="col-lg-5 if-input">
                        <input maxlength="20" id="nc-phone" placeholder="手机或固定电话" />
                        <p>如果是固定电话，格式如示例：0760-8888888</p>
                    </div>
                    <div class="col-lg-5 if-memo" id="ifm-phone">

                    </div>
                </div>
                <div class="row infoField">
                    <div class="col-lg-2 if-title">
                        行业类型
                    </div>
                    <div class="col-lg-5 if-input">
                        <input maxlength="100" id="nc-industry" placeholder="主营业务所属行业" />
                    </div>
                    <div class="col-lg-5 if-memo" id="ifm-industry">

                    </div>
                </div>
                <div class="row infoField">
                    <div class="col-lg-2 if-title">
                        企业官网(选填)
                    </div>
                    <div class="col-lg-5 if-input">
                        <input maxlength="200" id="nc-website" placeholder="企业官方网站地址" />
                    </div>
                    <div class="col-lg-5 if-memo-single" id="it-website">
                    </div>
                </div>
                <br />
                <div class="row sectionTitle">
                    <h5>认证资料</h5>
                </div>
                <div class="row sectionTip">
                    <div class="TLCertify ct-logo">天联认证</div>
                    <br />
                    天联认证服务是为了保证平台用户利益的重要措施之一，其目的是为了保证平台上的企业都是真实存在的组织团体。
                    认证通过的企业，在对应企业名称旁会显示显著标识，能显著增加自身的信誉。
                </div>
                <div class="row infoField">
                    <div class="col-lg-2 if-title">
                        组织机构代码
                    </div>
                    <div class="col-lg-5 if-input">
                        <input maxlength="20" id="nc-orgcode" />
                        <p>请输入9位组织机构代码，如12345678-9；或三证合一后18位的统一社会信用代码</p>
                    </div>
                    <div class="col-lg-5 if-memo" id="ifm-orgcode">

                    </div>
                </div>
                <div class="row infoField">
                    <div class="col-lg-2 if-title">
                        工商执照注册号
                    </div>
                    <div class="col-lg-5 if-input">
                        <input maxlength="20" id="nc-licencecode" />
                        <p>请填写工商营业执照上的注册号；或三证合一后18位的统一社会信用代码</p>
                    </div>
                    <div class="col-lg-5 if-memo" id="ifm-licencecode">
                    </div>
                </div>
                <div class="row infoField">
                    <div class="col-lg-2 if-title">
                        营业执照照片
                    </div>
                    <div class="col-lg-5">
                        <div class="row">
                            <div class="col-lg-6 if-pic" id="nc-licencepic">
                                <img src="/SiteUI/Imgs/picselector-bk.png" />
                            </div>
                            <div class="col-lg-6 if-pic-example">
                                <img src="/SiteUI/Imgs/bizlicence-example.jpg" />
                                <br />
                                <a class="LinkTo" href="/SiteUI/Imgs/bizlicence-example-big.jpg" target="_blank">点击查看样例</a>
                            </div>
                        </div>
                    </div>
                    <div class="col-lg-5">
                        扫描营业执照副本，手写<strong style="color:red">‘仅用于天联云认证’字样并加盖企业公章</strong>然后拍照上传
                        <br />
                        照片所有信息需清晰可见，内容真实有效，不得做任何修改。
                        <br />
                        照片支持.jpg .jpeg .bmp .gif .png格式，大小不超过8M。
                    </div>
                    <div class="col-lg-5 col-lg-offset-2 if-memo" id="ifm-licencepic">

                    </div>
                </div>
                <div class="row">
                    <div class="col-lg-5 col-lg-offset-2">
                        <div class="button btn-big" id="btnApplyCertify">提交认证申请</div>
                    </div>
                </div>
            </div>
        </div>
    </div>

</div>

<script>
    var NewCompany = {
        CertifyApply: {
            name: null,
            address: null,
            phone: null,
            industry: null,
            website: null,
            orgcode: null,
            licencecode: null,
            licencepic: null,
            parentorg:-1
        },
        IsTestingName: false,
        PhoneFormat: /(^1[3,4,5,7,8]{1}[0-9]{9}$)|(^\d{3,4}-\d{7,8}$)/,  //手机号或座机格式验证的正则,
        OrgcodeFormat: /(^\d{8}-\d{1}$)|(^[A-Za-z0-9]{18}$)/,//9位组织机构代码或三证合一后18位正则
        LicencecodeFormat: /(^\d{15}$)|(^[A-Za-z0-9]{18}$)/,//工商营业执照上的注册号15位或三证合一后18位正则
        WebsiteFormat: /^^(?=^.{3,255}$)(http(s)?:\/\/)?(www\.)?[a-zA-Z0-9][-a-zA-Z0-9]{0,62}(\.[a-zA-Z0-9][-a-zA-Z0-9]{0,62})+(:\d+)*(\/\w+\.\w+)*$/,//DNS规定，域名中的标号都由英文字母和数字组成，每一个标号不超过63个字符，也不区分大小写字母。标号中除连字符（-）外不能使用其他的标点符号。级别最低的域名写在最左边，而级别最高的域名写在最右边。由多个标号组成的完整域名总共不超过255个字符。
        testName: function () {
            var name = $("#nc-name").vl();
            if (!name.length > 0) {
                $("#ifm-name").vl("请填写企业全称").removeClass("checking");
            }
            else {
                $("#ifm-name").vl("正在检查企业名称是否可用").addClass("checking");
                NewCompany.IsTestingName = true;
                $.getJSON("/Company/FindCompany", { key: name }, NewCompany.testNameEnd);
            }
        },
        testNameEnd: function (rtn) {
            if (rtn.IsPositive && rtn.Data["companies"].length > 0) {
                $("#ifm-name").vl("此企业名称已经存在认证记录").removeClass("checking");
                //TODO:提示用户是否要申请加入
                NewCompany.CertifyApply.name = null;
            }
            else {
                $("#ifm-name").vl("此企业名称可以认证").addClass("success");
                NewCompany.CertifyApply.name = $("#ifm-name").vl().trim();
            }
            NewCompany.IsTestingName = false;
        },
        checkName: function () {
            if (NewCompany.IsTestingName == true) {
                return false;
            }
            else if (NewCompany.CertifyApply.name == null) {
                NewCompany.testName();
                return false;
            }
            else {
                $("#ifm-name").vl("");
                return true;
            }
        },
        checkIndustry: function () {
            var indsy = $("#nc-industry").vl();
            if (!indsy.length > 0) {
                $("#ifm-industry").vl("请填写正确的行业类型");
                return false;
            } else {
                $("#ifm-industry").vl("");
                return true;
            }
        },
        checkWebsite: function () {
            var website = $("#nc-website").vl();
            if (website.length>0&& website.substring(0, 7)!= "http://"){
                NewCompany.CertifyApply.website = "http://"+website;
            } else {
                NewCompany.CertifyApply.website = website;
            }
        },
        checkPhone: function () {
            var phone = $("#nc-phone").vl();
            if (!NewCompany.PhoneFormat.test(phone)) {
                $("#ifm-phone").vl("请填写正确的联系电话");
                return false;
            } else {
                $("#ifm-phone").vl("");
                return true;
            }
        },
        checkOrgCode: function () {
            var orgcode = $("#nc-orgcode").vl();
            if (!NewCompany.OrgcodeFormat.test(orgcode)) {
                $("#ifm-orgcode").vl("请输入正确的组织机构代码");
                return false;
            } else {
                $("#ifm-orgcode").vl("");
                return true;
            }
        },
        checkLicencecode: function () {
            var licencecode = $("#nc-licencecode").vl();
            if (!NewCompany.LicencecodeFormat.test(licencecode)) {
                $("#ifm-licencecode").vl("请输入正确的工商执照注册号");
                return false;
            } else {
                $("#ifm-licencecode").vl("");
                return true;
            }
        },
        checkAddress: function () {
            var address = $("#nc-address").vl();
            if (!address.length > 0) {
                $("#ifm-address").vl("请填写正确的注册地址");
                return false;
            } else {
                $("#ifm-address").vl("");
                return true;
            }

        },
        checkLicencePic: function () {
            if (NewCompany.CertifyApply.licencepic == null) {
                $("#ifm-licencepic").vl("请上传认证照片");
                return false;
            }
            else {
                $("#ifm-licencepic").vl("");
                return true;
            }
        },
        applyCertify: function () {
            //TODO:执行所有的前端检查
            if (NewCompany.checkName() & NewCompany.checkAddress() & NewCompany.checkPhone() & NewCompany.checkIndustry() & NewCompany.checkOrgCode() & NewCompany.checkLicencecode() & NewCompany.checkLicencePic()) {
                NewCompany.CertifyApply.name = $("#nc-name").vl();
                NewCompany.CertifyApply.address = $("#nc-address").vl();
                NewCompany.CertifyApply.phone = $("#nc-phone").vl();
                NewCompany.CertifyApply.industry = $("#nc-industry").vl();
                NewCompany.CertifyApply.orgcode = $("#nc-orgcode").vl();
                NewCompany.CertifyApply.licencecode = $("#nc-licencecode").vl();

                $.post("/Company/ApplyCertify", NewCompany.CertifyApply, NewCompany.applyEnd)
            }
        },
        applyEnd: function (rtn) {
            if (rtn.IsPositive) {
                success("申请成功", "您的申请已提交，稍后将有管理人员联系你核实相关信息")
                    .on("disposed", function (ev) { window.location = "/MyBiz/Dashbord"; });
            }
            else {
                error("申请失败", "您的申请未能成功提交,请检查您填写的企业信息或联系本平台管理人员（联系方式见页面下方）", 10);
            }
        },
        onLicencePicChange: function (ev) {
            switch (ev.Status) {
                case "imageLoaded":
                    $("#nc-licencepic>img").attr("src", ev.Item.thumbnail);
                    break;
                case "uploadEnd":
                    NewCompany.CertifyApply.licencepic = ev.Item.Result.path;
                    break;
                case "uploadFailure":
                    error("上传失败", "这通常是由于文件大小超过限制，请尝试更换小一点的图片");
                    break;
            }
        }
    };

    $(function () {
       var n = getUrlParam("companyname");
       if (n) {
           $("#nc-name").vl(n).select();
       }
        //获得组织机构父类
       var e = window.location.hash;
       NewCompany.CertifyApply.parentorg = e.substring(1, e.length);
       if (NewCompany.CertifyApply.parentorg) {
           $("#pageTitle>h4").vl("创建子公司");
       }

       var licencepic = new LiberUI.Uploader($("#nc-licencepic"))
                                   .option("FileType", "image/*")
                                   .option("MaxSize", 8*1024*1024)
                                   .update();
       licencepic.on("change", NewCompany.onLicencePicChange);

       if (User && User.mphone) {
          $("#nc-phone").vl(User.mphone);
       }
       $("#nc-name").blur(NewCompany.testName);
       $("#nc-phone").blur(NewCompany.checkPhone);
       $("#nc-industry").blur(NewCompany.checkIndustry);
       $("#nc-orgcode").blur(NewCompany.checkOrgCode);
       $("#nc-licencecode").blur(NewCompany.checkLicencecode);
       $("#nc-address").blur(NewCompany.checkAddress);
       $("#nc-website").blur(NewCompany.checkWebsite);
       $("#btnApplyCertify").on("click", NewCompany.applyCertify);
    })
</script>

